package com.ruoyi.index.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.index.domain.FhIndexPostcomments;
import com.ruoyi.index.service.IFhIndexPostcommentsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 发布评论Controller
 * 
 * @author ruoyi
 * @date 2024-11-11
 */
@RestController
@RequestMapping("/index/postcomments")
public class FhIndexPostcommentsController extends BaseController
{
    @Autowired
    private IFhIndexPostcommentsService fhIndexPostcommentsService;

    /**
     * 查询发布评论列表
     */
    @PreAuthorize("@ss.hasPermi('index:postcomments:list')")
    @GetMapping("/list")
    public TableDataInfo list(FhIndexPostcomments fhIndexPostcomments)
    {
        startPage();
        List<FhIndexPostcomments> list = fhIndexPostcommentsService.selectFhIndexPostcommentsList(fhIndexPostcomments);
        return getDataTable(list);
    }

    /**
     * 导出发布评论列表
     */
    @PreAuthorize("@ss.hasPermi('index:postcomments:export')")
    @Log(title = "发布评论", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FhIndexPostcomments fhIndexPostcomments)
    {
        List<FhIndexPostcomments> list = fhIndexPostcommentsService.selectFhIndexPostcommentsList(fhIndexPostcomments);
        ExcelUtil<FhIndexPostcomments> util = new ExcelUtil<FhIndexPostcomments>(FhIndexPostcomments.class);
        util.exportExcel(response, list, "发布评论数据");
    }

    /**
     * 获取发布评论详细信息
     */
    @PreAuthorize("@ss.hasPermi('index:postcomments:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(fhIndexPostcommentsService.selectFhIndexPostcommentsById(id));
    }

    /**
     * 新增发布评论
     */
    @PreAuthorize("@ss.hasPermi('index:postcomments:add')")
    @Log(title = "发布评论", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FhIndexPostcomments fhIndexPostcomments)
    {
        return toAjax(fhIndexPostcommentsService.insertFhIndexPostcomments(fhIndexPostcomments));
    }

    /**
     * 修改发布评论
     */
    @PreAuthorize("@ss.hasPermi('index:postcomments:edit')")
    @Log(title = "发布评论", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FhIndexPostcomments fhIndexPostcomments)
    {
        return toAjax(fhIndexPostcommentsService.updateFhIndexPostcomments(fhIndexPostcomments));
    }

    /**
     * 删除发布评论
     */
    @PreAuthorize("@ss.hasPermi('index:postcomments:remove')")
    @Log(title = "发布评论", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(fhIndexPostcommentsService.deleteFhIndexPostcommentsByIds(ids));
    }
}
